#include "core/system.h"

namespace core {
	System::System(const std::string& name, unsigned int taskFlags):
		util::Named(name),
		mSettings(name)
	{
		if (taskFlags != Task::NONE)
			mSystemUpdater.reset(new SystemUpdater(this, taskFlags));
	}

	System::~System() {
	}

	System::SystemInitializing::SystemInitializing(System* s): mSystem(s) {
	}

	System::SystemShuttingDown::SystemShuttingDown(System* s): mSystem(s) {
	}

	bool System::init() {
		mChan.broadcast(SystemInitializing(this));
		mLog.setPrefix("[" + getName() + "] ");
		mLog.add(new std::ofstream(getName() + ".log"));
		return true;
	}

	void System::update() {
	}

	void System::shutdown() {
		mChan.broadcast(SystemShuttingDown(this));
	}

	System::SystemUpdater::SystemUpdater(System* s, unsigned int taskFlags):
		Task(taskFlags),
		mSystem(s)
	{
	}

	void System::SystemUpdater::run() {
		mSystem->update();
	}
}
